/*
 * @Author: lei
 * @Description: C++11 thread库基本api使用:thread、joinable、join、detach、hardware_concurrency、
 * @FilePath: /code/thread.cc
 */

//g++ -o thread thread.cc -std=c++11 -lpthread 

#include <thread>
#include <iostream>
#include <string>
#include <utility>//std::move()

void print(int i,std::string s)
{
    while(i--)
        std::cout<<s<<std::endl;
}


int main()
{
    std::cout<<std::thread::hardware_concurrency()<<std::endl;
    std::string s("leiyx sb!");
    std::thread th(print,10,std::move(s));
    //std::thread th(print,10,std::ref(s));
    if(th.joinable())
        std::cout<<"th can join"<<std::endl;
    //一个线程必须被join或detach，且只能被join或detach一次
    std::cout<<s<<std::endl;//s 为空了
    //th.detach();
    th.join();
    return 0;
}